package server.container;

import server.pojo.Request;
import server.pojo.Response;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

public class MyHost implements BaseContainer {

    Map<String, MyContext> map = new HashMap<>();

    public MyHost(String key, MyEngine myEngine) {
        myEngine.add(key, this);
    }

    public void add(String key, MyContext myContext) {
        map.put(key, myContext);
    }

    public void invoke(Request request, Response response) {
        map.forEach(new BiConsumer<String, MyContext>() {
            @Override
            public void accept(String s, MyContext myContext) {
                if (request.getContextId() != null && request.getContextId().equals(s)) {
                    myContext.invoke(request, response);
                }
            }
        });
    }
}
